package com.jack.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.jack.Utils.DBUtil;

public class User_recomappDAO {
	private static Connection conn = null;
	private static PreparedStatement ps = null;
	private static ResultSet rs = null;
	public static void insert(int id,List<String> apps) {
		String sql = "insert into user_recomapp values (?,?)";
		StringBuffer sb = new StringBuffer();
		String appSession = null;
		int length = apps.size();
		if (length>0) {
			for (String app : apps) {
				sb.append(app);
				sb.append(",");
			}			
			sb.deleteCharAt(sb.length()-1);
			appSession = sb.toString();
		}else {
			appSession = null;
		}
		
		try {
			conn = DBUtil.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			ps.setString(2, appSession);
			int aftline = ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBUtil.closeConnection();
		}
	}
}
